package easy;

import java.util.Stack;

public class _155_MinStack {
    //使用额外变量保存最小值，在插入最小值时同时插入次小值以保证最小值弹出后次小值变为最小值的正确性
    /** initialize your data structure here. */
    Stack<Integer> stack  = new Stack<Integer>();
    int min = Integer.MAX_VALUE;

    public void push(int x) {
        if(x<=min){
            stack.push(min);
            min = x;
        }
        stack.push(x);
    }

    public void pop() {
        if(stack.pop()==min){
            min = stack.pop();
        }
    }

    public int top() {
        return stack.peek();
    }

    public int getMin() {
        return min;
    }
}
